package com.ylz.sjzx.sio.common.core.core.container;

import com.ylz.sjzx.sio.common.core.context.ApplicationUtils;
import com.ylz.sjzx.sio.common.core.core.IAdapter;
import com.ylz.sjzx.sio.common.core.core.SioBase;
import com.ylz.sjzx.sio.common.core.core.container.common.annotation.AdapterDesc;

import java.util.Map;
import java.util.Set;

/**
 * 容器扫描器.
 * 提供API自动扫描项目内部指定class子类,
 * 并获得对应的初始化对象list.
 */
public class AdapterContainer {

    AdapterContainer() {

        Set<IAdapter> adapters = ContainerScanner.scanAdapter();

        for (IAdapter adapter : adapters) {
            AdapterDesc desc = adapter.getClass().getAnnotation(AdapterDesc.class);
            String id = desc.id();
            SioBase.getInnerAdapterMap().put(id, ApplicationUtils.getBean(adapter.getClass()));
        }
    }

    public Map<String, IAdapter> getAdapterMap() {
        return SioBase.getInnerAdapterMap();
    }
}
